/*
package com.runfast.waimai.web.controller.business;

import com.runfast.common.web.entity.Result;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

*/
/**
 * ${DESCRIPTION}
 *
 * @author chenzheng
 * @create 2018-05-12 10:17
 **//*

@RestController("fileUploadController")
@RequestMapping("/server/fileUpload")
public class FileUploadController {
    @Value("${web.upload-path}")
    private String UPLOAD_FOLDER;
    private static Set<String> imageSet = new HashSet<String>();
    static{
        imageSet.add(".png");
        imageSet.add(".jpg");
        imageSet.add(".jpeg");
        imageSet.add(".gif");
        imageSet.add(".bmp");
    }
    @PostMapping("/upload")
    public Result upload(@RequestParam("upfile") MultipartFile upfile, boolean realpath) {
            Map<Object,Object> map=new HashMap<Object, Object>();
            if (upfile != null) {
                String extention = getExtention(upfile.getOriginalFilename());
                if (imageSet.contains(extention)) {
                    String newFileName = System.currentTimeMillis() + getExtention(upfile.getOriginalFilename());
                    String realPath = UPLOAD_FOLDER;
                    File file = new File(realPath);
                    if (!file.exists()) {
                        file.mkdir();
                    }
                    File dstFile = new File(realPath, newFileName);
                    try {
                        FileUtils.copyInputStreamToFile(upfile.getInputStream(), dstFile);
                        long fileSize = dstFile.length();
                        String fileName = UPLOAD_FOLDER + newFileName;

                    if(realpath){
                        realPath = dstFile.getPath();
                        map.put("realPath",realPath);
                    }
                    } catch (IOException e) {
                        e.printStackTrace();
                        Result.fail(null, "保存文件时,发生错误!");
                    }
                } else {
                    Result.fail(null, "只能上传图片");
                }

            } else {
                Result.fail(null, "请选择要上传的文件!");
            }
        return Result.ok(null,map);
    }
    */
/**
     * 获取文件后缀名
     * @param fileName
     * @return
     *//*

    private String getExtention(String fileName) {
        int pos = fileName.lastIndexOf(".");
        if(pos>0){
            fileName = fileName.substring(pos);
        }
        return fileName;
    }
}
*/
